<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="p"%>
<script>
	function dept_adddept(){
		var values=$getByName("deptId",$("#deptmain_div")).val();
		if(!values){
			$w.infoMsg('信息提示','请选择上级机构！');
			return false;
		}
		var str=ctx+"/platform/dept/DeptPage.page?actions=addShow&deptId="+values;
		$w.openDialog({title:'添加机构',w:390,h:200,url:str});
	}
	function dept_editdept(){
		var values=$getByName("deptId",$("#deptmain_div")).val();
		if(!values){
			$w.infoMsg('请选择机构！');
			return false;
		}else if(values=='root'){
			$w.infoMsg('不能修改根节点！');
			return false;
		}
		var str=ctx+"/platform/dept/DeptPage.page?actions=updateShow&deptId="+values;
		$w.openDialog({title:'修改机构',w:390,h:200,url:str});
	}
	function dept_deldept(){
		var values=$getByName("deptId",$("#deptmain_div")).val();
		if(!values){
			$w.infoMsg('请选择机构！');
			return false;
		}else if(values=='root'){
			$w.infoMsg('不能删除根节点！');
			return false;
		}
		var urls=ctx+"/platform/dept/DeptPage.page?actions=del&deptId="+values;
		$w.confirmMsg('确定删除？',function(r){
			if(r)
			$.ajax({type:"POST",url:urls,success:dept_deldeptOk});
		});
	}
	function dept_deldeptOk(d){
		if(d.state=='ok'){
			tree_afterDelNode("deptmain_tree");
			$getByName("deptId",$("#deptmain_div")).val("");
		}
	}
	
	function dept_sortdept(){
		var values=$getByName("deptId",$("#deptmain_div")).val();
		if(!values){
			$w.alertMsg('信息提示','请选择机构！');
			return false;
		}
		var path=ctx+"/platform/dept/DeptPage.page?actions=sortShow&parDeptId="+values;
		$w.openDialog({title:'机构排序',w:290,h:280,url:path});
	}
</script>
<div class="ui-toolBar" border="false" id="deptmain_div">
<p:hidden bind="deptId"/>
	<a href="#" class="easyui-linkbutton" onclick="dept_adddept()" data-options="plain:true,iconCls:'icon_add'">添加</a>
	<a href="#" class="easyui-linkbutton" onclick="dept_editdept()" data-options="plain:true,iconCls:'icon_edit'">修改</a>
	<a href="#" class="easyui-linkbutton" onclick="dept_deldept()" data-options="plain:true,iconCls:'icon_del'">删除</a>
	<a href="#" class="easyui-line"></a>
	<a href="#" class="easyui-linkbutton" onclick="dept_sortdept()" data-options="plain:true,iconCls:'icon_sort'">排序</a>
</div>

<div style="width:100%;height:5px;"></div>
<div id="deptmain_tree"></div>
<script>
$("#deptmain_tree").dynatree({
	rootVisible: false,
	initAjax: { 
              url: ctx+"/platform/dept/DeptTreeJson.json?expand=true" 
		},
	onLazyRead: function(dtnode){
              dtnode.appendAjax({
                  url: ctx+"/platform/dept/DeptTreeJson.json?nodeId="+ dtnode.data.key
              });
	},
	onActivate: function(dtnode){
		$getByName("deptId",$("#deptmain_div")).val(dtnode.data.key);
	}
			
});
</script>